import { Controller, Post, Body, UseGuards, Request } from '@nestjs/common';
import { UsersService } from './users.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import {
  UpdatePasswordDto,
  UpdatePasswordResponseDto,
} from './dto/update-password.dto';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiBearerAuth,
} from '@nestjs/swagger';

@ApiTags('用户')
@Controller('users')
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  @UseGuards(JwtAuthGuard)
  @Post('update-password')
  @ApiBearerAuth()
  @ApiOperation({ summary: '更新密码', description: '更新当前登录用户的密码' })
  @ApiResponse({
    status: 200,
    description: '密码更新成功',
    type: UpdatePasswordResponseDto,
  })
  @ApiResponse({ status: 401, description: '未授权' })
  async updatePassword(@Request() req, @Body() body: UpdatePasswordDto) {
    const success = await this.usersService.updatePassword(
      req.user.id,
      body.newPassword,
    );
    return { success };
  }
}
